{include file="public/layout" /}

<body class="bodystyle" style="cursor: default; -moz-user-select: inherit;min-width:auto;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="min-width:auto;">
    <div class="flexigrid">
        <form class="form-horizontal" id="postForm" action="{:url('Shop/order_send_operating', ['_ajax'=>1])}" method="post">
            <input type="hidden" name="order_id" value="{$OrderData.order_id}">
            <input type="hidden" name="order_code" value="{$OrderData.order_code}">
            <input type="hidden" name="users_id" value="{$OrderData.users_id}">
            <input type="hidden" name="consignee" value="{$OrderData.consignee}">
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                            <tr>
                                <th class="sign w10" axis="col0">
                                    <div class="tc"></div>
                                </th>
                                <th abbr="article_title" axis="col3" class="w10">
                                    <div class="tc">基本信息</div>
                                </th>
                                <th abbr="ac_id" axis="col4">
                                    <div class="item-title" style="margin-bottom: 0px;line-height: 26px;"><a class="back" style="margin: 1px 0px 0px 0px;" href="{:url('Shop/order_details',array('order_id'=>$OrderData['order_id']))}" title="返回详情"><i class="fa fa-angle-double-left"></i>返回</a></div>
                                </th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>

            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">
                        <label>订单编号</label>
                    </dt>
                    <dd class="opt">          
                        {$OrderData.order_code}
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label>订单类型</label>
                    </dt>
                    <dd class="opt">          
                        {$OrderData.prom_type_name}
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label>下单时间</label>
                    </dt>
                    <dd class="opt">          
                        {$OrderData.add_time|MyDate='Y-m-d H:i:s',###}
                    </dd>
                </dl>
                {eq name="$OrderData.prom_type" value="0"}
                    <dl class="row">
                        <dt class="tit">
                            <label>发货方式</label>
                        </dt>
                        <dd class="opt">          
                            <select name="prom_type" id="prom_type">
                                <option value="0" {eq name="$OrderData.prom_type" value="0"} selected="selected" {/eq}>
                                    录入物流单号
                                </option>
                                <option value="1" {eq name="$OrderData.prom_type" value="1"} selected="selected" {/eq}>
                                    无需物流
                                </option>
                            </select>
                            <span class="err"></span>
                            <p class="notic"></p>
                        </dd>
                    </dl>
                {else/}
                    <input type="hidden" name="prom_type" value="1">
                {/eq}

                <div class="{eq name='$OrderData.prom_type' value='1'}none{/eq}" id="ShippingInfo">
                    <dl class="row">
                        <dt class="tit">
                            <label>物流公司</label>
                        </dt>
                        <dd class="opt">          
                            <span id="express_name_new">{$OrderData.express_name}</span>
                            &nbsp;<a href="javascript:void(0);" onclick="Express();" class="ncap-btn ncap-btn-green">选择快递</a>
                            <input type="hidden" name="express_name" value="{$OrderData.express_name|default=''}" id="express_name">
                            <input type="hidden" name="express_id" value="{$OrderData.express_id|default=''}" id="express_id"/>
                            <input type="hidden" name="express_code" value="{$OrderData.express_code|default=''}" id="express_code">
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label>配送费用</label>
                        </dt>
                        <dd class="opt">          
                            ￥{$OrderData.shipping_fee}
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label><em>*</em>配送单号</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" value="{$OrderData.express_order}" name="express_order" id="express_order" class="input-txt">
                        </dd>
                    </dl>
                </div>

                <div class="{if condition='$OrderData.prom_type == 0 && $OrderData.prom_type_virtual == false'}none{/if}" id="VirtualDelivery">
                    <dl class="row">
                        <dt class="tit">
                            <label>给买家回复</label>
                        </dt>
                        <dd class="opt">          
                            <textarea rows="5" cols="60" name="virtual_delivery" style="height:60px;">{$OrderData.virtual_delivery}</textarea>
                            <span class="err"></span>
                            <p class="notic"></p>
                        </dd>
                    </dl>
                </div>
            </div>
            
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                        <tr>
                            <th class="sign w10" axis="col0">
                                <div class="tc"></div>
                            </th>
                            <th abbr="article_title" axis="col3" class="w10">
                                <div class="tc">收货信息</div>
                            </th>
                            <th abbr="ac_id" axis="col4">
                                <div class=""></div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="ncap-form-default">
                {eq name="$OrderData.prom_type" value="0"}
                    <dl class="row">
                        <dt class="tit">
                            <label>收货人</label>
                        </dt>
                        <dd class="opt">          
                            {$OrderData.consignee}
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label>联系方式</label>
                        </dt>
                        <dd class="opt">          
                            {$OrderData.mobile}
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label>收货地址</label>
                        </dt>
                        <dd class="opt">          
                            {$OrderData.country} {$OrderData.province} {$OrderData.city} {$OrderData.district} {$OrderData.address}
                        </dd>
                    </dl>
                {/eq}
                <dl class="row">
                    <dt class="tit">
                        <label>订单留言</label>
                    </dt>
                    <dd class="opt">          
                        {$OrderData.user_note}
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label>管理员备注</label>
                    </dt>
                    <dd class="opt">
                        {$OrderData.admin_note}
                        <span class="err"></span>
                        <p class="notic"></p>
                    </dd>
                </dl>
            </div>
            <div class="ncap-form-default">
                <div class="bot" style="padding-bottom:0px;">
                    <a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">
                        {eq name="$OrderData['order_status']" value='1'}
                            确认发货
                        {/eq}
                        {eq name="$OrderData['order_status']" value='2'}
                            修改保存
                        {/eq}
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">

    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        $('#prom_type').change(function(){
            var prom_type = $(this).val();
            if (1 == prom_type) {
                $('#ShippingInfo').hide();
                $('#VirtualDelivery').show();
            } else {
                $('#ShippingInfo').show();
                $('#VirtualDelivery').hide();
            }
        });
    });

    // 物流公司选择框
    function Express(){
        var url = "{:url('Shop/order_express')}";
        //iframe窗
        layer.open({
            type: 2,
            title: '选择快递',
            shadeClose: false,
            maxmin: false, //开启最大化最小化按钮
            area: ['60%', '80%'],
            content: url
        });
    }

    // 选中地址，关闭物流公司弹框
    function express(obj, express_id){
        var express_name = $(obj).parent().find('#express_name_'+express_id).val();
        var express_code = $(obj).parent().find('#express_code_'+express_id).val();
        $('#express_id').val(express_id);
        $('#express_name').val(express_name);
        $('#express_name_new').html(express_name);
        $('#express_code').val(express_code);
        layer.closeAll();
    }

    // 表单提交
    function checkForm() {
        if(0 == $('#prom_type').val() && $('input[name=express_order]').val() == ''){
            showErrorMsg('配送单号不能为空！');
            $('input[name=express_order]').focus();
            return false;
        }

        var _parent = parent;

        layer.confirm('此操作不可恢复，确认发货？', {
            title: false,
            btn: ['确定','取消']
        },function(){
            layer_loading('正在处理');
            $.ajax({
                type: "POST",
                url: $('#postForm').attr('action'),
                data: $('#postForm').serialize(),
                dataType: 'json',
                success: function (res) {
                    if(res.code == 1){
                        if (!res.data.email && !res.data.mobile) {
                            layer.closeAll();
                            layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                _parent.window.location.reload();
                            });
                        } else {
                            if (res.data.email) SendEmail(res.data.email);
                            if (res.data.mobile) SendMobile(res.data.mobile);
                            layer.closeAll();
                            layer.msg('发货成功', {icon: 1, time: 1000}, function(){
                                _parent.window.location.reload();
                            });
                        }
                    } else {
                        layer.closeAll();
                        layer.alert(res.msg, {icon: 2, title:false});
                        return false;
                    }
                },
                error:function(){
                    layer.closeAll();
                    layer.alert(ey_unknown_error, {icon: 2, title:false});
                }
            });
        });
    }

    function SendEmail(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }

    function SendMobile(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }
</script> 
{include file="public/footer" /}